//matrix.cpp
#include <stdio.h>
#include "Matrix.h"

using namespace std;

unsigned int matrices = 0;

Matrix::Matrix(const int n, const int ld) : m_columnCount(n), m_rowCount(n), m_ld(ld)
{
	Fill();
}

Matrix::Matrix(const int cols, const int rows, const int ld) : m_columnCount(cols), m_rowCount(rows), m_ld(ld)
{
	Fill();
}

void Matrix::Fill()
{
	int matrixSize = m_ld*m_rowCount;
	m_dpAdr = new double[matrixSize];
matrices++;
	for(int i = 0; i < matrixSize; ++i)
	{
		m_dpAdr[i] = i+1;
	}	
}


//const double *Matrix::GetMatrix() const
double const *Matrix::GetMatrix() const
{
	return m_dpAdr;
}

double *Matrix::GetMatrix() 
{
	return m_dpAdr;
}

int Matrix::GetColumnCount() const
{
	return m_columnCount;
}

int Matrix::GetRowCount() const
{
	return m_rowCount;
}

int Matrix::GetLD() const
{
	return m_ld;
}

std::ostream& operator<< (std::ostream &out, const Matrix &self)
{
	for(const double *d(self.m_dpAdr), *de(d + (self.m_ld * self.m_rowCount)); d != de; ++d) {
		out << *d << ",";
	}
	return out;
}

Matrix::~Matrix()
{
matrices--;
	delete [] m_dpAdr;
}
